#pragma once

#include "buscan.hpp"
#include "can_msg.hpp"

const int id_list_size = 32;

/**
 * @brief can device
 */
class robot_can_dev: private robot_driver
{
    friend class robot_can_bus;
    friend void hw_rx_thread_entry(void *p);
public:
    robot_can_dev(robot_can_bus* b);
    virtual ~robot_can_dev();

    void open();
    void add_id(uint32_t id);
    int read_block(int pos, void *buffer,int size);
    int read(int pos, void *buffer,int size);
    int write(int pos, const void *buffer,int size);
    void read_clear();
    
private:
    robot_can_bus* bus;
    struct rt_semaphore r_sem; 
    
    robot_fifo<can_msg> msg;

    uint32_t id_list[id_list_size];
    int id_list_len;

    robot_list device_on_bus;
};